package diaodu.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xkh.xkh.MyApplication;
import com.xkh.xkh.R;

import java.util.ArrayList;
import java.util.List;

import diaodu.dto.WaterDispatch;
import gongqing.views.adapters.DeviceAdapter;
import shuiyuqing.model.BasicInfoModel;
import shuiyuqing.network.beans.IrrBAWaterGate;
import utils.TimeUtil;

import static shuiyuqing.model.BasicInfoModel.getwaterGateByStadia;

/**
 * Created by Administrator on 2017/6/3.
 */

public class DispatchAdapter extends BaseAdapter {

    List<WaterDispatch> dispatchList = new ArrayList<>();

    public void setDispatchList(List<WaterDispatch> dispatchList) {
        this.dispatchList = dispatchList;
    }

    @Override
    public int getCount() {
        return dispatchList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;

        if (convertView == null) {
            convertView = View.inflate(MyApplication.share(), R.layout.item_dispatch, null);
            viewHolder = new ViewHolder();
            viewHolder.receiveName = (TextView) convertView.findViewById(R.id.receiveName);
            viewHolder.time = (TextView) convertView.findViewById(R.id.time);
            viewHolder.sendName = (TextView) convertView.findViewById(R.id.sendName);
            viewHolder.gateName = (TextView) convertView.findViewById(R.id.gateName);
            viewHolder.control = (TextView) convertView.findViewById(R.id.control);
            viewHolder.icon_new = (TextView) convertView.findViewById(R.id.icon_new);
            viewHolder.icon_new.setTypeface(MyApplication.iconfont);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        WaterDispatch dispatch = dispatchList.get(i);
        viewHolder.receiveName.setText(dispatch.getReceiveName());
        viewHolder.time.setText(TimeUtil.getTimeByDate2(dispatch.getSendTime().getTime()));
        if (TimeUtil.isToday(dispatch.getSendTime()))
        {
            viewHolder.icon_new.setVisibility(View.VISIBLE);
        }
        else
        {
            viewHolder.icon_new.setVisibility(View.GONE);
        }
        viewHolder.sendName.setText(dispatch.getSendName());
        IrrBAWaterGate  gate = BasicInfoModel.getwaterGateByStadia(dispatch.getWatergateCode());
        viewHolder.gateName.setText(gate.getWatergateName());
        viewHolder.control.setText(dispatch.getHeightChange());

        return convertView;
    }



    class ViewHolder
    {
        TextView receiveName ;
        TextView time;
        TextView sendName;
        TextView gateName ;
        TextView control ;
        TextView icon_new;
    }
}
